import React, { Component } from 'react';
import moment from 'moment';
import Child from './index_child';
import { Form, Button, message } from 'antd';

/**
 * props:主要用于组件之间的参数传递
 * 生命周期：componetWillMount->render->componentDidMount
 */
class Parent extends Component {
    state = {
        name: '马云',
    }

    handleSubmit = () => {
        this.formRef.validateFields((err, fieldValue) => {
            if (err) return;
            if (fieldValue.time) {
                fieldValue.startTime = moment(fieldValue.time).format('YYYY-MM-DD');
                delete fieldValue.time;
            }
            console.log('value',fieldValue);
        });
    }

    // 点击
    // handleClick = (name) => {
    //     message.success(`${name},恭喜您输入正确！`);
    // }


    render() {
        const { name } = this.state;
        return (
            <>
                <Child
                    customerName={name}
                    // handleClick={this.handleClick}
                    getForm={form => { this.formRef = form }}
                />
                <Button
                    type='primary'
                    style={{ marginTop: '2%' }}
                    onClick={this.handleSubmit}
                >
                    提交
                </Button>
            </>
        );
    }
}

export default Parent;